package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Score;
import cn.wolfcode.trip.base.domain.User;
import cn.wolfcode.trip.base.mapper.ScoreMapper;
import cn.wolfcode.trip.base.service.IScoreService;
import cn.wolfcode.trip.base.util.UserContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 用户积分实现类
 */
@Service
public class ScoreServiceImpl implements IScoreService {
    @Autowired
    private ScoreMapper scoreMapper;

    //获取当前用户的积分
    public Score getUserScore() {
        //获取当前用户
        User currentUser = UserContext.getCurrentUser();
        Score s = scoreMapper.selectByPrimaryKey(currentUser.getId());
        return scoreMapper.selectByPrimaryKey(currentUser.getId());
    }

    //更新获取的积分
    public void updateOwnScore(Score score) {
        scoreMapper.updateOwnScore(score);
    }

    //保存获取的积分
    public void save(Score score) {
        scoreMapper.insert(score);
    }

    //根据用户id获取积分信息
    public Score selectScoreById(Long id) {
        return scoreMapper.selectByPrimaryKey(id);
    }

    /**
     * 更改支付积分
     * @param score
     */
    @Override
    public void updata(Score score) {
        scoreMapper.updateScoreByPay(score);
    }
}
